﻿	var option=[];
	option['en'+'dr']="Departure:Drive";
	option['zh-cn'+'dr']="出发地：驾驶";
	option['zh-tw'+'dr']="出發地：駕駛";
	option['fr'+'dr']="Départ: Drive";
	option['de'+'dr']="Abreise: Drive";
	option['es'+'dr']="Salida: Conducción";
	option['ja'+'dr']="出発：車";
	
	option['en'+'wk']="Departure:Walk";
	option['zh-cn'+'wk']="出发地：散步";
	option['zh-tw'+'wk']="出發地：散步";
	option['fr'+'wk']="Départ: Randonnée pédestre";
	option['de'+'wk']="Abreise: Wandern";
	option['es'+'wk']="Salida: Paseos";
	option['ja'+'wk']="出発：ウォーキング";
	
	option['en'+'av']="Arrival";
	option['zh-cn'+'av']="目的地";
	option['zh-tw'+'av']="目的地";
	option['fr'+'av']="Arrivée";
	option['de'+'av']="Anreise";
	option['es'+'av']="Llegada";
	option['ja'+'av']="到着";
	
	option['en'+'nt']="Notes";
	option['zh-cn'+'nt']="注解";
	option['zh-tw'+'nt']="注解";
	option['fr'+'nt']="Annotation";
	option['de'+'nt']="Notiz";
	option['es'+'nt']="Notas";
	option['ja'+'nt']="注解";

	option['en'+'dt']="Departure Time";
	option['zh-cn'+'dt']="出发时间";
	option['zh-tw'+'dt']="出發時間";
	option['fr'+'dt']="Heure de départ";
	option['de'+'dt']="Abflugzeit";
	option['es'+'dt']="Hora salida";
	option['ja'+'dt']="出発時刻";

	option['en'+'at']="Arrival Time";
	option['zh-cn'+'at']="到达时间";
	option['zh-tw'+'at']="到達時間";
	option['fr'+'at']="Heure d'arrivée";
	option['de'+'at']="Ankunftszeit";
	option['es'+'at']="Hora de llegada";
	option['ja'+'at']="到着時刻";

	option['en'+'ts']="Total Seconds";
	option['zh-cn'+'ts']="总秒数";
	option['zh-tw'+'ts']="總秒數";
	option['fr'+'ts']="Total secondes";
	option['de'+'ts']="Insgesamt Sekunden";
	option['es'+'ts']="Total Segundos";
	option['ja'+'ts']="トータル秒";

	option['en'+'sm']="Sum Distance (m)";
	option['zh-cn'+'sm']="总距离（米）";
	option['zh-tw'+'sm']="總距離（米）";
	option['fr'+'sm']="Distance totale (m)";
	option['de'+'sm']="Gesamt (m)";
	option['es'+'sm']="Distancia total (m)";
	option['ja'+'sm']="総距離（オス）";
	
	option['en'+'sp']="* Walking Speed = 5.4 kilometer/hour, or 3.4 mile/hour";
	option['zh-cn'+'sp']="* 步行速度 = 5.4公里/小时，或3.4英里/小时";
	option['zh-tw'+'sp']="* 步行速度 = 5.4公里/小時，或3.4英里/小時";
	option['fr'+'sp']="* La vitesse de marche = 5,4 km/heure, soit 3,4 mile/heure";
	option['de'+'sp']="* Wandern Geschwindigkeit = 5,4 km/h, oder 3,4 Meile/Stunde";
	option['es'+'sp']="* Paseos Velocidad = 5,4 kilometros / hora, o 3.4 millas/hora";
	option['ja'+'sp']="* ウォーキング速度 = 5.4キロ/時、または3.4マイル/時";
	
	var vck=getCookie ( "lizoft" );
	var si='en';
	if(vck!=null){
		var va=vck.split("@@");
		si=va[4];
	}
	try{		
		var xmlDoc=null;
		if (window.ActiveXObject)
		{// code for IE
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		}
		else if (document.implementation.createDocument)
		{// code for Mozilla, Firefox, Opera, etc.
		xmlDoc=document.implementation.createDocument("","",null);
		}
		else
		{
		alert('Your browser cannot handle this script');
		}
	}catch(e){
		alert("Please configure your browser security settings: internet options\n\tRouteQuik reminding " + e.name + "! Error detail as such, \n\t" + e.message); 
		//return;
	}
	
	var s=9*3600;
	var m=0;
	try{
		var fso = new ActiveXObject('Scripting.FileSystemObject'); 
	}catch(e){
		alert("Please configure your browser security settings: internet options\n\t" + e.name + "! Error detail as such, \n\t" + e.message); 
		//return;
	}
	var currentDir=fso.getFolder(".");
	var filename=prompt("Load XML route data from, ", currentDir + "\\routes.xml");
	if(filename.length<1) exit;
	
	if (xmlDoc!=null)
	{
		xmlDoc.async="true"; 
		xmlDoc.onreadystatechange=function(){if(xmlDoc.readyState!=4)return false;};
		if(!fso.FileExists(filename))
			alert("File not existing: " + filename);
		else{		
			xmlDoc.load(filename);
			document.write("<body><div style=\"border: 1px solid #979797; overflow:auto; background-color: #e5e3df; width: 90%; margin: auto; margin-left: 5%; margin-top: 5%;margin-bottom: 1px\">");
			document.write("<table id=\"data\" align=\"center\" border=\"1\" bordercolor=\"#cccccc\" cellpadding=\"3\" cellspacing=\"0\" width=\"98%\">");
			document.write("<thead id=\"downTblHead\">");
			document.write("<th style=\"width:15%\">"+option[si+'dr']+"</th>");
			document.write("<th style=\"width:15%\">"+option[si+'wk']+"</th>");
			document.write("<th style=\"width:15%\">"+option[si+'av']+"</th>");
			document.write("<th>"+option[si+'nt']+"</th>");
			document.write("<th>"+option[si+'dt']+"</th>");
			document.write("<th>"+option[si+'at']+"</th>");
			document.write("<th>"+option[si+'ts']+"</th>");
			document.write("<th>"+option[si+'sm']+"</th></thead>");
			var x=xmlDoc.getElementsByTagName("route");
			for (var i=0;i<x.length;i++)
			{ 
				if(i%2==0)
					document.write("<tr bgcolor=\"#ffffff\">");
				else
					document.write("<tr bgcolor=\"#ececec\">");
					
				document.write("<td style=\"width:15%\" align=\"left\">");		
				document.write(x[i].getElementsByTagName("drive")[0].childNodes[0].nodeValue);			
				document.write("</td>");
				
				document.write("<td style=\"width:15%\" align=\"left\">");
				document.write(x[i].getElementsByTagName("walk")[0].childNodes[0].nodeValue);
				document.write("</td>");
				
				document.write("<td style=\"width:15%\" align=\"left\">");
				document.write(x[i].getElementsByTagName("arrive")[0].childNodes[0].nodeValue);
				document.write("</td>");
				
				document.write("<td align=\"left\">");
				//alert(x[i].getElementsByTagName("note")[0].childNodes[0].nodeValue);
				document.write(x[i].getElementsByTagName("note")[0].childNodes[0].nodeValue);
				document.write("</td>");
				
				var sv=parseInt(x[i].getElementsByTagName("time")[0].childNodes[0].nodeValue);
				var mv=x[i].getElementsByTagName("meters")[0].childNodes[0].nodeValue;
				
				m+=mv.indexOf("km")>0?parseFloat(mv)*1000:parseFloat(mv);
					
				document.write("<td align=\"center\" nowrap=\"true\">");
				document.write("<input style=\"text-align: center\" id=\"r"+ i +"\" size=\"10\" onchange=\"update(this," + x.length + "," +i +")\" type=\"textbox\" value=\"" + SecondToTime(s)  + "\"/>");
				document.write("</td>");

				s+=sv;
				
				document.write("<td id=\"t" + i + "\" align=\"center\">");
				document.write(SecondToTime(s));
				document.write("</td>");
				
				document.write("<td id=\"s" + i + "\" align=\"center\">");
				document.write(sv);
				document.write("</td>");
				
				document.write("<td id=\"m" + i + "\" align=\"center\">");
				document.write(m);
				document.write("</td>");
				
				document.write("</tr>");
			}
			document.write("</table><br> ");
			document.write(option[si+'sp']);
			document.write("</div></body>");
		}
	}
	
	function SecondToTime(sec){
		var min = Math.floor(sec/60) + (sec%60>30?1:0);
		var hr = Math.floor(min/60);
		min = min % 60;
		var t = two(min);
		hr = hr % 24;
		t = two(hr) + ":" + t;
		return t;
	}
	function two(x) {return ((x>9)?"":"0")+x;}
	
	function update(obj, len, id){
		var tbl=document.getElementById("data");
		var val = obj.value;
		var _reg = new RegExp(/^([01][0-9]|2[0-3]):[0-5][0-9]$/);
		obj.style.background="white";
		if(!_reg.test(val)){
			obj.style.background="red";
			alert(obj.value + " is not a correct time format !");
			return;
		}
		
		var txt2=val.split(":");		
		if(id>0){
			var tval=document.getElementById("t" + (id-1)).innerText;
			var txt=tval.split(":");
			var v1=parseInt(txt[0]) * 60 + parseInt(txt[1]);
			var v2=parseInt(txt2[0]) * 60 + parseInt(txt2[1]);
			if (v1>v2){
				obj.style.background="yellow";
				alert("Warning:\n\t" + obj.value + " is earlier than " + tval + "!\t\n\nPlease confirm ...\n");
			}			
		}
		
		var sc=document.getElementById("s" + id).innerText;
		var base=txt2[0] * 3600 + txt2[1] * 60 + parseInt(sc);
		document.getElementById("t" + id).innerText=SecondToTime(base);
		
		for(var ix=id+1;ix<len;ix++){
			sc=document.getElementById("s" + ix).innerText;
			document.getElementById("r" + ix).value=SecondToTime(base);	
			document.getElementById("r" + ix).style.background="white";
			base+=parseInt(sc);
			document.getElementById("t" + ix).innerText=SecondToTime(base);
		}
	}